/*
* Renderer.java
* Copyright (C) 2003
*
* $Id: Renderer.java,v 1.6 2005/01/12 00:37:13 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
using System;
using refexport_t = Suake2.UI.client.refexport_t;
namespace Suake2.UI.render
{
	
	/// <summary> Renderer
	/// 
	/// </summary>
	/// <author>  cwei
	/// </author>
	public class Renderer
	{
		public static System.String DefaultName
		{
			get
			{
				return ((drivers.Count == 0))?null:((Ref) drivers[0]).Name;
			}
			
		}
		public static System.String PreferedName
		{
			get
			{
				return ((drivers.Count == 0))?null:((Ref) drivers[drivers.Count - 1]).Name;
			}
			
		}
		public static System.String[] DriverNames
		{
			get
			{
				if ((drivers.Count == 0))
					return null;
				int count = drivers.Count;
				System.String[] names = new System.String[count];
				for (int i = 0; i < count; i++)
				{
					names[i] = ((Ref) drivers[i]).Name;
				}
				return names;
			}
			
		}
		
		internal static System.Collections.ArrayList drivers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(3));
		
		
		public static void  register(Ref impl)
		{
			if (impl == null)
			{
				throw new System.ArgumentException("Ref implementation can't be null");
			}
			if (!drivers.Contains(impl))
			{
				drivers.Add(impl);
			}
		}
		
		/// <summary> Factory method to get the Renderer implementation.</summary>
		/// <returns> refexport_t (Renderer singleton)
		/// </returns>
		public static refexport_t getDriver(System.String driverName)
		{
			// find a driver
			Ref driver = null;
			int count = drivers.Count;
			for (int i = 0; i < count; i++)
			{
				driver = (Ref) drivers[i];
				if (driver.Name.Equals(driverName))
				{
					return driver.GetRefAPI();
				}
			}
			// null if driver not found
			return null;
		}
		static Renderer()
		{
			{
				try
				{
					try
					{
						//UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
						System.Type.GetType("net.java.games.jogl.GL");
						//UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
						System.Type.GetType("jake2.render.JoglRenderer");
					}
					//UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
					catch (System.Exception e)
					{
						// ignore the jogl drivers if runtime not in classpath
					}
					try
					{
						//UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
						System.Type.GetType("org.lwjgl.opengl.GL11");
						//UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
						System.Type.GetType("jake2.render.LWJGLRenderer");
					}
					//UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
					catch (System.Exception e)
					{
						// ignore the lwjgl driver if runtime not in classpath
					}
					try
					{
						//UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
						System.Type.GetType("net.java.games.jogl.GL");
						//UPGRADE_TODO: The differences in the format  of parameters for method 'java.lang.Class.forName'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
						System.Type.GetType("jake2.render.FastJoglRenderer");
					}
					//UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
					catch (System.Exception e)
					{
						// ignore the fastjogl drivers if runtime not in classpath
					}
				}
				//UPGRADE_NOTE: Exception 'java.lang.Throwable' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
				catch (System.Exception e)
				{
					SupportClass.WriteStackTrace(e, Console.Error);
				}
			}
		}
	}
}